package com.zy.service.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zy.dao.UserDao;
import com.zy.entity.Course;
import com.zy.entity.Subject;
import com.zy.entity.User;
import com.zy.entity.Video;
import com.zy.service.UserService;
@Component
@Transactional
public class UserServiceImpl implements UserService{
	@Autowired
	private UserDao ud;
	public UserDao getUd() {
		return ud;
	}
	public void setUd(UserDao ud) {
		this.ud = ud;
	}
	//登录
	@Override
	public boolean login(User u,HttpServletRequest request) {
		User us = ud.login(u);
		if(us!=null){
			request.getSession().setAttribute("user", us);
			return true;
		}else{
			return false;
		}
	}
	//更改用户资料
	@Override
	public void updateUser(User u) {
		ud.updateUser(u);
	}
	//根据id查询用户
	@Override
	public User selectUserById(User u) {
		return ud.selectUserById(u);
	}
	//根据id修改头像
	@Override
	public void upLoadImage(User u) {
		ud.upLoadImage(u);
	}
	//修改密码
	@Override
	public void updatePassword(User u) {
		ud.updatePassword(u);
	}
	//查询所有邮箱
	@Override
	public List<User> selectAllEmail() {
		return ud.selectAllEmail();
	}
	//注册邮箱密码
	@Override
	public void insertUser(User u) {
		ud.insertUser(u);
	}
	//重置密码
	@Override
	public void updatePasswordByEmail(User u) {
		ud.updatePasswordByEmail(u);
	}
	//根据email查询用户
	@Override
	public User selectUserByEmail(User u) {
		return ud.selectUserByEmail(u);
	}
	//科目三表查询
	@Override
	public Subject selectSubjectById(Subject s) {
		return ud.selectSubjectById(s);
	}
	//根据id查询视频
	@Override
	public Video selectVideoById(Video v) {
		return ud.selectVideoById(v);
	}
	//根据id查询课程
	@Override
	public Course selectCourseById(Course c) {
		return ud.selectCourseById(c);
	}

}
